﻿@model SMECustomerWebsite.Models.ViewModels.CustomerManager.CustomerPortfolioViewModel

@Html.Action("CustInfo", "System")
<!-- start accordion -->
<div class="row">
    <div class="col-md-12">
        @Html.Action("SubMenuAlertBadbank", "System")
        <div class="x_panel">
            <div class="x_title">
                <div class="col-lg-8 col-md-9 col-sm-8">
                    @Html.Action("SubMenuAlertCust", "System")
                    <h2 class="col-lg-8">@SMECustomerWebsite.Core.Resources.Resource.AlertCardOverdue.ToUpper()</h2>
                    <p class="col-lg-6">@SMECustomerWebsite.Core.Resources.Resource.AlertCardOverdueDesc</p>
                </div>
                <ul class="nav navbar-right panel_toolbox">
                    @Html.Action("BusinessDateInfo", "System", new { name = "TBL_ALERT_CARD_OVERDUE" })
                    <li>
                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                @if (Model.CurrentUser.GroupIdentifier.Equals("3"))
                {
                    <div class="col-md-6 cm-search-box">
                        @using (Html.BeginForm("ExportDataCustomerOverdue", "CustomerAlert", FormMethod.Post, new { @class = "sme-form-export" }))
                        {
                            <input type="submit" name="btnExportLicensing" style="width: 140px;" value="Export to excel" id="exportLicensing" class="btn btn-success right" />
                        }
                    </div>
                }
                @switch (Model.CurrentUser.GroupIdentifier)
                {
                    case "1":
                        <table id="cm-alert-badbank" class="table custom_table table-bordered table-striped jambo_table">
                            <thead class="headings">
                                <tr>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                    <th class="column-title">DAO</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                    <th class="column-title">ACCTNO</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.OvdLevelHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NoOverdueHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOverdueHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MinPayHeader (VND)</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.OverdueBalanceHeader (VND)</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateBaddebtHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                        break;
                    case "2":
                    <table id="cm-alert-badbank" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                <th class="column-title">DAO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title">ACCTNO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.OvdLevelHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NoOverdueHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOverdueHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MinPayHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.OverdueBalanceHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateBaddebtHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "3":
                    <table id="cm-alert-badbank" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">DAO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title">ACCTNO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.OvdLevelHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NoOverdueHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOverdueHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MinPayHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.OverdueBalanceHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateBaddebtHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "4":
                    <table id="cm-alert-badbank" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title">ACCTNO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.OvdLevelHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NoOverdueHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateOverdueHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MinPayHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.OverdueBalanceHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.DateBaddebtHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    default:
                        break;
                }
            </div>
        </div>
    </div>
</div>

@section scripts
{
    <script src="~/Scripts/custom_search_table.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="~/scripts/datepicker/moment/moment.min.js"></script>
    <script src="~/scripts/datepicker/datepicker/daterangepicker.js"></script>
    <script src="~/scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var lcColumn = [
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "INFO", "className": 'column-title details-control', "bSortable": false }];
            var lcLenCol = 9;
            var lcCifCol = 0;
            switch (@Model.CurrentUser.GroupIdentifier) {
                case 1:
                    lcColumn =  [
                            { "sName": "REGION", "bSortable": false },
                            { "sName": "BRANCH", "bSortable": false },
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "INFO", "className": 'column-title details-control', "bSortable": false }];
                    lcLenCol = 13;
                    lcCifCol = 4;
                    break;
                case 2:
                    lcColumn =  [
                            { "sName": "BRANCH", "bSortable": false },
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "INFO", "className": 'column-title details-control', "bSortable": false }];
                    lcLenCol =12;
                    lcCifCol = 3;
                    break;
                case 3:
                    lcColumn = [
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "DATE MOVING IN", "bSortable": false },
                            { "sName": "INFO", "className": 'column-title details-control', "bSortable": false }];
                    lcLenCol = 11;
                    lcCifCol = 2;
                    break;
                default:
                    break;
            }
            var tablebadbank = $('#cm-alert-badbank').DataTable({
                "order": [[0, 'asc']],
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                rowsGroup: [0, 1, 2, 3],
                "sAjaxSource": '@Url.Action("AlertCardOverdueData", "CustomerAlert")',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns":lcColumn,
                "aoColumnDefs": [{
                    "sClass": "column-title",
                    "aTargets": [lcLenCol],
                    "mRender": function (data, type, full) {
                        return '<a class=\"btn btn-primary btn-xs\" onclick=\"showCustomerInfo(\'' + full[lcCifCol] + '\');\"><i class="fa fa-info"></i></a>';
                    }
                }],
                initComplete: function () {
                    this.api().columns().every(function () {
                        var column = this;
                        switch (column.context[0].aoHeader[0][column.index()].cell.innerText) {
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper())':
                                createFilterRegion(column, '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone)');
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper())':
                                createFilterBranch(column);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader.ToUpper())':
                                createFilterMSBOName(column, 1);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.NoOverdueHeader)':
                                createFilterRangeMulti(column, 1, 1000,1,1);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.OverdueBalanceHeader) (VND)':
                                createFilterRangeMulti(column, -1000000000, 0, 1, 2);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.MinPayHeader) (VND)':
                                createFilterRangeMulti(column, -1000000000, 0, 1, 3);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.OvdLevelHeader)':
                                var option = [{ id: '', text: 'All' },{ id: 'Bad Debt', text: 'Bad Debt' }, { id: 'OVD', text: 'OVD' }, { id: 'OVD30', text: 'OVD30' }, { id: 'OVD60', text: 'OVD60' }]
                                createFilterCustType(column,option);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.DateOverdueHeader)':
                                createFilterDateMulti(column,null, null, 1);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.DateBaddebtHeader)':
                                createFilterDateMulti(column,null, null, 2);
                                break;
                            case 'DAO':
                                createFilterMSBOName(column, 2);
                                break;
                            default:
                                if (column.index() < lcLenCol) {
                                    var select = $('<input type="text" class="filtet-table">')
                                                            .appendTo($(column.header()))
                                                            .on('keyup change', function () {
                                                                column.search(this.value).draw();
                                                            });
                                }
                                break;

                        }
                    });
                },
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            });
        })
    </script>
}
